<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    img {
      width: 100%;
      height: 100%;
      display: block;
    }

    .box {
      width: 450px;

      margin: 50px;
      display: flex;
      flex-direction: column;

      position: relative;
    }

    .box>.show {
      width: 450px;
      height: 450px;
      border: 1px solid #333;
      position: relative;
    }

    .box>.show>.mask {
      width: 200px;
      height: 200px;
      background-color: yellow;
      opacity: .4;
      position: absolute;
      top: 0px;
      left: 0px;

      display: none;
    }

    .box>.list {
      width: 100%;
      flex: 1;

      display: flex;
      justify-content: flex-start;
      align-items: center;

      box-sizing: border-box;
      padding: 20px;
    }

    .box>.list>p {
      width: 54px;
      height: 54px;
      border: 1px solid #333;
      margin-right: 10px;
    }

    .box>.list>p.active {
      border-color: red;
    }

    .box>.enlarge {
      width: 400px;
      height: 400px;
      position: absolute;
      top: 0;
      left: 101%;
      background: url(../images/1.big.jpg) no-repeat;
      background-size: 800px 800px;
      background-position: 0 0;
      display: none;
    }
  </style>
</head>

<body>

  <div class="box">
    <div class="show">
      <img src="../images/1.jpg" alt="">
      <div class="mask"></div>
    </div>
    <div class="list">
      <p class="active">
        <img src="../images/1.small.jpg" showImg="../images/1.jpg" enlargeImg="../images/1.big.jpg" alt="">
      </p>
      <p>
        <img src="../images/2.small.jpg" showImg="../images/2.jpg" enlargeImg="../images/2.big.jpg" alt="">
      </p>
    </div>
    <div class="enlarge"></div>
  </div>
  <script>
      let maskEle = document.querySelector(".mask");
      let showEle = document.querySelector(".show");
      let boxEle = document.querySelector(".box");
      let enlargeEle = document.querySelector(".enlarge");
      showEle.onmouseenter = function (){
        maskEle.style.display = "block" ; 
        enlargeEle.style.display = "block" ; 
      }
      showEle.onmouseleave = function (){
        maskEle.style.display = "none" ; 
        enlargeEle.style.display = "none" ; 
      }
      showEle.onmousemove = function ( event ){
        let e = event || window.event ; 
        let x = e.clientX - boxEle.offsetLeft - maskEle.offsetWidth/2 ; 
        let y = e.clientY - boxEle.offsetTop - maskEle.offsetHeight/2 ; 
        if ( x <= 0 ){
            x = 0 ;
        }
        if ( x >= showEle.offsetWidth - maskEle.offsetWidth ){
            x = showEle.offsetWidth - maskEle.offsetWidth ; 
        }
        if ( y <= 0 ){
            y = 0 ;
        }
        if ( y >= showEle.offsetHeight - maskEle.offsetHeight ){
            y = showEle.offsetHeight - maskEle.offsetHeight ; 
        }   
        maskEle.style.left = x + "px" ; 
        maskEle.style.top = y + "px" ; 
        let str = getStyle(enlargeEle,"backgroundSize");
        let arr = str.split(" ");
        let bigWidth = parseInt(arr[0]) ; 
        let bigHeight =  parseInt(arr[1]);
        xx = x * bigWidth / showEle.offsetWidth ;
        yy = y * bigHeight / showEle.offsetHeight ; 
        enlargeEle.style.backgroundPosition = `-${xx}px -${yy}px` ;
        
      }
      let pEles = document.querySelectorAll(".list p");
      let imgEle = document.querySelector(".show img");
      pEles.forEach(function ( pEle , key ){
            pEle.onclick = function (){
                pEles.forEach(function(item,k){
                    if ( k == key ){
                        item.classList.add("active");
                    } else {
                        item.classList.remove("active");
                    }
                });
                imgEle.src = `../images/${key+1}.jpg` ; 
                enlargeEle.style.backgroundImage = `url(../images/${key+1}.big.jpg)`; 
            }
        });
      function getStyle(ele,styleName){
        if( window.getComputedStyle){
            return getComputedStyle(ele,null)[styleName] ; 
        } else {
            return ele.currentStyle[styleName] ; 
        }
      }
  </script>
</body>

</html>